/*
 * @Author: lixu
 * @Date: 2020-09-23 17:25:46
 * @Last Modified by: lixu
 * @Last Modified time: 2020-09-23 17:31:29
 * @description: 所有异常都捕获
 */
import {
  ExceptionFilter,
  Catch,
  ArgumentsHost,
  HttpException,
  HttpStatus,
} from '@nestjs/common';
import { Response } from 'express';

@Catch()
export class AllExceptionFilter implements ExceptionFilter {
  catch(exception: any, host: ArgumentsHost) {
    console.log('all 捕获', exception);
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();

    response.status(500).json({
      statusCode: 1501,
      data: {
        message: 'server error'
      }
    })
  }
}
